<?php 

namespace application\view;

require_once("common/view/Page.php");
require_once("login/view/LoginView.php");
require_once("register/view/RegisterView.php");
require_once("comments/view/CommentView.php");

class View {

	/**
	 * @var \login\view\LoginView $loginView
	 */
	private $loginView;

	/**
	 * @var \register\view\RegisterView $registerView
	 */
	private $registerView;

	/**
	 * @var \posts\view\PostView $postView
	 */
	private $postView;
	
	/**
	 * @var \comments\view\CommentView $commentView
	 */
	private $commentView;

	public function __construct(\login\view\LoginView $loginView, 
								\register\view\RegisterView $registerView,
								\posts\view\PostView $postView,
								\comments\view\CommentView $commentView) {
		$this->loginView = $loginView;
		$this->registerView = $registerView;
		$this->postView = $postView;
		$this->commentView = $commentView;
	}
	
	/**
	 * Assemble and return \common\view\Page
	 * @return \common\view\Page
	 */
	public function getLoggedOutPage() {
		$html = $this->postView->getHTMLPosts();
		$footer = $this->loginView->loginHTMLForm();
		$footer .= $this->registerView->registerHTMLForm();
		return new \common\view\Page("Logged out", $html, $footer);
	}

	/**
	 * Assemble and return \common\view\Page
	 * @return \common\view\Page
	 */
	public function getLoggedInPage() {
		$html = $this->postView->getHTMLPosts();
		$footer = $this->loginView->getLogoutButton();
		$footer .= $this->postView->getPostButton();		
		return new \common\view\Page("Logged in", $html, $footer);
	}

	/**
	 * Assemble and return \common\view\Page
	 * @return \common\view\Page
	 */
	public function getAddingPostPage() {
		$html = $this->postView->getHTMLPosts();
		$footer = $this->loginView->getLogoutButton();
		$footer .= $this->getHomeButton();
		$footer .= $this->postView->getAddPosts();		
		return new \common\view\Page("Logged in", $html, $footer);
	}

	/**
	 * Assemble and return \common\view\Page
	 * @return \common\view\Page
	 */
	public function getSinglePostPage($id) {
		$html = $this->postView->getSinglePost($id);
		$html .= $this->commentView->getHTMLComments($id);
		$footer = $this->loginView->getLogoutButton();
		$footer .= $this->getHomeButton();
		$footer .= $this->commentView->getAddComments();		
		return new \common\view\Page("Logged in", $html, $footer);
	}

	/**
	 * Assemble and return \common\view\Page
	 * @return \common\view\Page
	 */
	public function getSinglePostLoggedOut($id) {
		$html = $this->postView->getSinglePost($id);
		$html .= $this->commentView->getHTMLComments($id);
		$footer = $this->loginView->loginHTMLForm();
		$footer .= $this->registerView->registerHTMLForm();
		return new \common\view\Page("Logged out", $html, $footer);
	}

	private function getHomeButton() {
		$html = "<div id='homeButton'>
					<a class='footerButton' href='./'>Home</a>
				</div>";
		return $html;
	}
}